<template>
  <div>
    <div slot="header" class="clearfix">
      <span style="float: left; padding: 3px 0">软件变更监控策略列表</span>
      <el-button style="float: right; padding: 3px 0" type="text" icon="el-icon-refresh" @click="cshufosx">刷新
      </el-button>
      <el-button style="float: right; padding: 3px 3px;margin:0 5px" icon="el-icon-plus" type="text" @click="addClick" v-if="showFlag">
        新增</el-button>
    </div>
    <com-table :tableData="tableData" url="app" keyName="app" :has-data="hasData" :table-head-list="tableHeadList"
      :total-count="totalCount" :page-num="pageNum" :page-size="pageSize" :page-sizes="pageSizes"
      :table-loading="loading" :table-height="tableHeight" :is-show-select="true" :page-show="false" :handle-show="true"
      :merge-flag="false" :modifys="true" :baddtsd="false" @setSearchHeight="setTableHeight" @openDialog="openDialog"
      :deletebtn="false" ref="comTable" @deleteHandle="deleteHandle" :ifShowOnline="true" addOnline="状态"
      @isOnline="isOnline">
    </com-table>

  </div>
</template>
<script>
import ComTable from "../../components/table/comTable";
export default {
  name: "mabDevice",
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      pageSizes: [5, 10, 20, 100],
      totalCount: 0,
      tableData: [], // 表格数据
      options: [],
      tableHeight: "", // 表格高度
      dialogTitle: "",
      hasData: true,
      loading: false, // 数据加载状态遮罩
      checkList: [],
      tableHeadList: [
        {
          columnComment: "策略名称",
          columnName: "name",
        },
        // {
        //   columnComment: "状态",
        //   columnName: "state",
        //   typeCollection: "stateEnum",
        // },
        {
          columnComment: "创建人",
          columnName: "creator",
        },
        {
          columnComment: "创建时间",
          columnName: "enableTime",
        },
      ],
      dialogControl: false,
      showFlag:true,
    };
  },
  components: {
    ComTable,
  },
  created() {
    this.setTableHeight();
    this.getTableData();
  },
  methods: {
    isOnline(val, row) {
      console.log(val, row, "34");
      row.Root.Policy.disable = val
      let params = {
        Policy: {
          Root: {
            Policy: row.Root.Policy,
          },
          creator: "secadm",
          enableTime: "",
          name: row.Root.Policy.name,
          rowIndex: row.Root.Policy.rowIndex,
          state: val,
        }
      }
      this.$postForJson("/sjrj/policy/softwarechanged", params).then(jsonData => {
        console.log(jsonData, "sss");
        this.$message({
          type: "success",
          message: "提交成功！",
        });
         this.getTableData()
      })

    },
    addClick() {
      this.$router.push({
        path: "/SystemMonitoringFrom",
        name: "SystemMonitoringFrom",
        params: {
          type: "Software",
          row: {},
        },
      });
    },
    deleteHandle(row) {
      console.log(row);
      this.$confirm("确认删除？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功！",
          });
        })
        .catch((_) => { });
    },
    // 列表
    getTableData() {
      this.$get("/sjrj/policy/softwarechanged").then((res) => {
        console.log(res, "sss");
        this.tableData = res.data.data;
        if(this.tableData.length >0){
          this.showFlag = false;
        }
      });
    },
    cshufosx() {
      this.getTableData()
    },
    //新建与修改
    openDialog(type, row) {
      console.log("aaa");
      this.$router.push({
        path: "/SystemMonitoringFrom",
        name: "SystemMonitoringFrom",
        params: {
          type: "Software",
          row: row,
        },
      });
    },
    dialogClosed() { },
    addTerminal() {
      this.dialogControl = false;
      this.$message({
        type: "success",
        message: "新增成功！",
      });
    },
    modifyTerminal() {
      this.dialogControl = false;
      this.$message({
        type: "success",
        message: "修改成功！",
      });
    },
    delegods() {
      this.$confirm("确认删除？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功！",
          });
        })
        .catch((_) => { });
    },
    setTableHeight() {
      let clientHeiht =
        window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 110;
    },
  },
};
</script>

<style scoped>
.el-checkbox-group {
  display: flex;
  flex-direction: column;
}
.el-select {
  width: 100%;
}
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
</style>